package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.MealCalendar;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.MealCalendarService;

@RestController
@RequestMapping("/mealcalendar")
public class MealCalendarController {

    @Autowired
    private MealCalendarService mealCalendarService;

    /**
     * 获取指定时间范围的膳食日历
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return 包含膳食日历列表的 ResponseBean
     */
    @GetMapping("/daterange")
    public ResponseBean<List<MealCalendar>> getMealCalendarByDateRange(
            @RequestParam String startDate,
            @RequestParam String endDate) {
        List<MealCalendar> mealCalendars = mealCalendarService.getMealCalendarByDateRange(startDate, endDate);
        return new ResponseBean<>(mealCalendars);
    }

    /**
     * 获取某一天的膳食安排
     * @param date 日期
     * @return 包含膳食安排列表的 ResponseBean
     */
    @GetMapping("/date/{date}")
    public ResponseBean<List<MealCalendar>> getMealsByDate(@PathVariable String date) {
        List<MealCalendar> mealCalendars = mealCalendarService.getMealsByDate(date);
        return new ResponseBean<>(mealCalendars);
    }

    /**
     * 添加膳食安排
     * @param mealCalendar 膳食安排对象
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addMealToCalendar(@RequestBody MealCalendar mealCalendar) {
        boolean result = mealCalendarService.addMealToCalendar(mealCalendar);
        return new ResponseBean<>(result);
    }

    /**
     * 更新膳食安排
     * @param mealCalendar 更新后的膳食安排对象
     * @return 更新结果的 ResponseBean
     */
    @PutMapping("/update")
    public ResponseBean<Boolean> updateMealCalendar(@RequestBody MealCalendar mealCalendar) {
        boolean result = mealCalendarService.updateMealCalendar(mealCalendar);
        return new ResponseBean<>(result);
    }

    /**
     * 删除膳食安排
     * @param id 膳食安排的唯一标识符
     * @return 删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Boolean> deleteMealFromCalendar(@PathVariable Integer id) {
        boolean result = mealCalendarService.deleteMealFromCalendar(id);
        return new ResponseBean<>(result);
    }
    /**
     * 根据时间和餐食种类筛选
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @param type 餐食种类
     * @return 包含符合条件的膳食日历列表的 ResponseBean
     */
    @GetMapping("/searchByDateRangeAndType")
    public ResponseBean<List<MealCalendar>> getMealCalendarsByDateRangeAndType(
            @RequestParam String date,
            @RequestParam String type) {
        List<MealCalendar> mealCalendars = mealCalendarService.getMealCalendarsByDateRangeAndType(date, type);
        return new ResponseBean<>(mealCalendars);
    }
}